﻿using System;
using System.IO;
using System.Drawing;
using System.Xml;
using System.Windows.Forms;
using ElectronicWMSA.Comm.ClassFiles;

namespace ElectronicWMSA.Warehouse
{
    public partial class Warehouse_OptimizationFrm : Form
    {
        private string strWhere = "";
        private string WarehouseCode = "";
        public Warehouse_OptimizationFrm()
        {
            InitializeComponent();
            #region
            this.dataGridView1.AllowUserToResizeColumns = false;
            this.dataGridView1.AllowUserToResizeRows = false;
            int H1 = 0;
            int H2 = 0;
            if (File.Exists("SytemConfig.xml"))
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load("SytemConfig.xml");
                foreach (XmlNode item in xmldoc.GetElementsByTagName("DOC"))
                {
                    foreach (XmlNode items in item.ChildNodes)
                    {
                        if (items.Name == "H1")
                            H1 = Convert.ToInt32(items.InnerText.Trim());
                        else if (items.Name == "H2")
                            H2 = Convert.ToInt32(items.InnerText.Trim());
                    }
                }
            }
            int SH = Screen.PrimaryScreen.Bounds.Height;
            int SW = Screen.PrimaryScreen.Bounds.Width;
            if (SH == 768 && SW == 1366)
                dataGridView1.RowTemplate.Height = H1;
            else if (SH == 1080 && SW == 1920)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH == 1050 && SW == 1680)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH > 1050)
                dataGridView1.RowTemplate.Height = H2;
            else if (SH == 768 && SW == 1024)
                dataGridView1.RowTemplate.Height = H1;
            else
                dataGridView1.RowTemplate.Height = H1;
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.  
            SetStyle(ControlStyles.DoubleBuffer, true);
            #endregion
        }

        private void Warehouse_OptimizationFrm_Load(object sender, EventArgs e)
        {
            this.strWhere = "";
            this.pageControl1.PageCurrent = 1;
            this.pageControl1.PageSize = 500;
            this.pageControl1.Bind();
        }
        private int DBind()
        {
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "PD_Layout";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.pageControl1.PageCurrent;
            pageData.PageSize = this.pageControl1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.pageControl1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.pageControl1.bindingNavigator.BindingSource = pageControl1.bindingSource;
            this.dataGridView1.AutoGenerateColumns = false;
            this.dataGridView1.DataSource = this.pageControl1.bindingSource;
            SystemVariable.DataGridViewStyle(dataGridView1);
            dataGridView1.RowsDefaultCellStyle.Font = new Font("微软雅黑", 4, FontStyle.Regular);
            dataGridView1.Rows[0].DefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
            dataGridView1.Rows[dataGridView1.Rows.Count - 1].DefaultCellStyle.Font = new Font("微软雅黑", 6, FontStyle.Regular);
            dataGridView1.Rows[0].DefaultCellStyle.BackColor = System.Drawing.Color.MediumSeaGreen;
            dataGridView1.Rows[dataGridView1.RowCount - 1].DefaultCellStyle.BackColor = System.Drawing.Color.MediumSeaGreen;
            return pageData.TotalCount;
        }
        Color Color_value = System.Drawing.Color.White;
        private int pageControlU_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBind();
        }

        private void BtnClearLine_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
        }

        #region 库存优化
        private void btnOptimization_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
            this.dataGridView1.Rows[10].Cells[3].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[4].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[5].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[11].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[12].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[10].Style.BackColor = System.Drawing.Color.Red;

            this.dataGridView1.Rows[30].Cells[35].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[36].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[37].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[38].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[27].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[26].Style.BackColor = System.Drawing.Color.Yellow;

            this.dataGridView1.Rows[35].Cells[35].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[36].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[37].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[40].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[44].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[43].Style.BackColor = System.Drawing.Color.Green;
        }

        private void btnPostionFulled_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
            this.dataGridView1.Rows[10].Cells[3].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[4].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[5].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[11].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[12].Style.BackColor = System.Drawing.Color.Red;
            this.dataGridView1.Rows[10].Cells[10].Style.BackColor = System.Drawing.Color.Red;
        }

        private void btnPostionFulling_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
            this.dataGridView1.Rows[30].Cells[35].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[36].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[37].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[38].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[27].Style.BackColor = System.Drawing.Color.Yellow;
            this.dataGridView1.Rows[30].Cells[26].Style.BackColor = System.Drawing.Color.Yellow;
        }

        private void btnPostionNull_Click(object sender, EventArgs e)
        {
            this.pageControl1.Bind();
            this.dataGridView1.Rows[35].Cells[35].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[36].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[37].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[40].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[44].Style.BackColor = System.Drawing.Color.Green;
            this.dataGridView1.Rows[35].Cells[43].Style.BackColor = System.Drawing.Color.Green;
        }

        private void btnPostion_Click(object sender, EventArgs e)
        {

        }
        #endregion

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
